defmodule Anagram do
  @doc """
  Returns all candidates that are anagrams of, but not equal to, 'base'.
  """
  @spec match(String.t(), [String.t()]) :: [String.t()]
  def match(base, candidates) do
    #IEx.Info.info candidates
    candidates
    |> Enum.filter(&is_angram?(String.downcase(base), String.downcase(&1)))

  end

  defp is_angram?(base, candidate) when base == candidate, do: false
  defp is_angram?(base, candidate) do
    #IO.inspect String.graphemes(base) -- String.graphemes(candidate)
    #IO.inspect String.graphemes(candidate) -- String.graphemes(base)
    diff_bc = String.graphemes(base) -- String.graphemes(candidate)
    diff_cb = String.graphemes(candidate) -- String.graphemes(base)
    
    diff_bc == diff_cb
  end

end
